using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;

namespace BumbleGame
{
    public class ScrollingBackground
    {
        // class ScrollingBackground
        private Vector2 screenpos, origin, texturesize;
        private Texture2D BGtexture;
        private int screenheight;

        // ScrollingBackground.Load
        public void Load(GraphicsDevice Device, Texture2D
        BackgroundTexture)
        {
            BGtexture = BackgroundTexture;
            screenheight = BGtexture.Height;
            int screenwidth = BGtexture.Width;
            // Set the origin so that we're drawing from the
            // center of the top edge
            origin = new Vector2(BGtexture.Width / 2, 0);
            // Set the screen position to the center of the screen.
            screenpos = new Vector2(screenwidth / 2, screenheight / 2);
            // Offset to draw the second texture, when necessary.
            texturesize = new Vector2(0, BGtexture.Height);
        }

        // ScrollingBackground.Update
        public void Update(float scrollY)
        {
            screenpos.Y += scrollY;
            screenpos.Y = screenpos.Y % BGtexture.Height;
        }

        // ScrollingBackground.Draw
        public void Draw(SpriteBatch Batch)
        {
            // Draw the texture, if it is still onscreen
            if (screenpos.Y < screenheight)
            {
                Batch.Draw(BGtexture, screenpos, null,
                     new Color(255, 255, 255, (byte)BumbleGame.Game1.gSaturate), 0, origin, 1, SpriteEffects.None, 0f);
            }
            // Draw the texture a second time, behind the first,
            // to create the scrolling illusion
            Batch.Draw(BGtexture, screenpos - texturesize, null,
                 new Color(255, 255, 255, (byte)BumbleGame.Game1.gSaturate), 0, origin, 1, SpriteEffects.None, 0f);
        }
    }

}
